/*    */ package com.engine;
/*    */ 
/*    */ import java.io.File;
/*    */ import java.io.IOException;
/*    */ import java.io.PrintStream;
/*    */ import javax.sound.sampled.AudioFormat;
/*    */ import javax.sound.sampled.AudioInputStream;
/*    */ import javax.sound.sampled.AudioSystem;
/*    */ import javax.sound.sampled.DataLine.Info;
/*    */ import javax.sound.sampled.FloatControl;
/*    */ import javax.sound.sampled.FloatControl.Type;
/*    */ import javax.sound.sampled.LineUnavailableException;
/*    */ import javax.sound.sampled.SourceDataLine;
/*    */ import javax.sound.sampled.UnsupportedAudioFileException;
/*    */ 
/*    */ public class AePlayWave
/*    */ {
/*    */   private String filename;
/*    */   private Position curPosition;
/* 20 */   private final int EXTERNAL_BUFFER_SIZE = 524288;
/*    */ 
/*    */   public AePlayWave(String wavfile)
/*    */   {
/* 27 */     this.filename = wavfile;
/* 28 */     this.curPosition = Position.NORMAL;
/*    */   }
/*    */ 
/*    */   public AePlayWave(String wavfile, Position p) {
/* 32 */     this.filename = wavfile;
/* 33 */     this.curPosition = p;
/*    */   }
/*    */ 
/*    */   public void run()
/*    */   {
/* 38 */     File soundFile = new File(this.filename);
/* 39 */     if (!soundFile.exists()) {
/* 40 */       System.err.println("Wave file not found: " + this.filename);
/* 41 */       return;
/*    */     }
/*    */ 
/* 44 */     AudioInputStream audioInputStream = null;
/*    */     try {
/* 46 */       audioInputStream = AudioSystem.getAudioInputStream(soundFile);
/*    */     } catch (UnsupportedAudioFileException e1) {
/* 48 */       e1.printStackTrace();
/* 49 */       return;
/*    */     } catch (IOException e1) {
/* 51 */       e1.printStackTrace();
/* 52 */       return;
/*    */     }
/*    */ 
/* 55 */     AudioFormat format = audioInputStream.getFormat();
/* 56 */     SourceDataLine auline = null;
/* 57 */     DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
/*    */     try
/*    */     {
/* 60 */       auline = (SourceDataLine)AudioSystem.getLine(info);
/* 61 */       auline.open(format);
/*    */     } catch (LineUnavailableException e) {
/* 63 */       e.printStackTrace();
/* 64 */       return;
/*    */     } catch (Exception e) {
/* 66 */       e.printStackTrace();
/* 67 */       return;
/*    */     }
/*    */ 
/* 70 */     if (auline.isControlSupported(FloatControl.Type.PAN)) {
/* 71 */       FloatControl pan = (FloatControl)auline
/* 72 */         .getControl(FloatControl.Type.PAN);
/* 73 */       if (this.curPosition == Position.RIGHT)
/* 74 */         pan.setValue(1.0F);
/* 75 */       else if (this.curPosition == Position.LEFT) {
/* 76 */         pan.setValue(-1.0F);
/*    */       }
/*    */     }
/* 79 */     auline.start();
/* 80 */     int nBytesRead = 0;
/* 81 */     byte[] abData = new byte[524288];
/*    */     try
/*    */     {
/* 84 */       while (nBytesRead != -1) {
/* 85 */         nBytesRead = audioInputStream.read(abData, 0, abData.length);
/* 86 */         if (nBytesRead >= 0)
/* 87 */           auline.write(abData, 0, nBytesRead);
/*    */       }
/*    */     } catch (IOException e) {
/* 90 */       e.printStackTrace();
/* 91 */       return;
/*    */     } finally {
/* 93 */       auline.drain();
/* 94 */       auline.close();
/*    */     }
/*    */   }
/*    */ 
/*    */   static enum Position
/*    */   {
/* 23 */     LEFT, RIGHT, NORMAL;
/*    */   }
/*    */ }

/* Location:           F:\16 2\SQ.jar
 * Qualified Name:     com.engine.AePlayWave
 * JD-Core Version:    0.6.0
 */